package cn.wen.bases.framework.spring;

import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Title：Spring Test.
 * <p>
 * Description：提供Spring初始化与获取Bean. 
 * <p>
 * Copyright：Copyright (c) 2010-2012
 * 
 * @author <a href="mailto:ct_wen@qq.com">ctwen</a>, 温承瑭
 * @version Revision：1.0 Date：2012/1/1 Description：初完成。
 *          <p>
 */
public final class TestSpring {

    private static AbstractApplicationContext ac;

    public static void start() {
	if (ac == null) load(); // Spring上下文初始化……
	ac.start();
    }

    public static void start(String... resource) {
	if (ac == null) load(resource); // Spring上下文初始化……
	ac.start();
    }

    public static void load() {
	load("application*.xml", "config/**/application-*.xml");
    }

    public static void load(String... resource) {
	if (ac == null) ac = new ClassPathXmlApplicationContext(resource);
    }

    public static Object getBean(String bn) {
	return ac.getBean(bn);
    }

    public static <T> T getBean(String bn, Class<T> clz) {
	return ac.getBean(bn, clz);
    }

}
